package pres.man.interview.thread;

import java.util.concurrent.*;

/**
 * 线程池原理
 *
 * @Author MAN
 * @Date 2021-01-18-15:15
 */
public class ThreadPoolExecutorPrinciple {
    public static void main(String[] args) {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(2, 3, 3, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1), new ThreadPoolExecutor.AbortPolicy());

        Future<Integer> future = poolExecutor.submit(() -> {
            int sleep = 3;
            try {
                TimeUnit.SECONDS.sleep(sleep);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return sleep;
        });

        try {
            Integer integer = future.get();
            System.out.println(integer);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }


    }
}
